#cache
$execute if data storage dab:system gameContents.bow[{id:"$(id)"}].cache.components run return run function dab:system/register/bow/item_compiler/bow_from_cache {id:"$(id)",can_use_count:$(can_use_count)}

#run
summon armor_stand ~ ~ ~ {HandItems:[{id:"bow",count:1,components:{enchantments:{levels:{"dab:generic_bow":1},show_in_tooltip:false},enchantment_glint_override:false}},{}],Tags:[register.bow.compiler],Marker:1b,Invisible:1b,Small:1b}

#读取
$item modify entity @n[tag=register.bow.compiler,type=armor_stand,distance=..1] weapon.mainhand [{function:"copy_custom_data",source:{type:"storage",source:"dab:system"},ops:[{op:"replace","source":"gameContents.bow[{id:\"$(id)\"}]",target:"temp"}]},{function:"set_lore",mode:"append",lore:[{"text":""}]},{function:"set_components",components:{"!max_damage":{}}}]

#修改与应用修饰器
$execute as @n[tag=register.bow.compiler,type=armor_stand,distance=..1] run data modify entity @s HandItems[0].components."minecraft:item_model" set from storage dab:system gameContents.bow[{id:"$(id)"}].item_model
execute as @n[tag=register.bow.compiler,type=armor_stand,distance=..1] run data modify entity @s HandItems[0].components."minecraft:custom_data" set from entity @s HandItems[0].components."minecraft:custom_data".temp
$data modify entity @n[tag=register.bow.compiler,type=armor_stand,distance=..1] HandItems[0].components."minecraft:custom_data".can_use_count set value $(can_use_count)
data remove entity @n[tag=register.bow.compiler,type=armor_stand,distance=..1] HandItems[0].components."minecraft:custom_data".custom_model_data
data remove entity @n[tag=register.bow.compiler,type=armor_stand,distance=..1] HandItems[0].components."minecraft:custom_data".item_modifier
$execute if data storage dab:system gameContents.bow[{id:"$(id)"}].item_modifier as @n[tag=register.bow.compiler,type=armor_stand,distance=..1] run function dab:system/register/bow/item_compiler/apply_modifier with storage dab:system gameContents.bow[{id:"$(id)"}]

#生成掉落物
summon item ~ ~ ~ {Item:{id:"poisonous_potato",count:1},Tags:[summon]}
data modify entity @n[tag=summon,type=item,distance=..1] Item set from entity @n[tag=register.bow.compiler,type=armor_stand,distance=..1] HandItems[0]

#写入缓存
$data modify storage dab:system gameContents.bow[{id:"$(id)"}].cache.components set from entity @n[tag=register.bow.compiler,type=armor_stand,distance=..1] HandItems[0].components

tag @n[tag=summon,type=item,distance=..1] remove summon
kill @n[type=armor_stand,tag=register.bow.compiler,distance=..1]